package com.demo.controller;

import com.demo.bean.Area;
import com.demo.common.Result;
import com.demo.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: lixiaodong
 * @Description:  三级联动模拟
 * @Date: 2022/9/15 15:12
 * @Parms:
 * @ReturnType:
 */
@Slf4j
@Controller
@RequestMapping("/list")
@Api(tags = "三级联动模拟")
public class AreaController  extends BaseController{
	@Autowired
	AreaService areaService;

	@ApiOperation(value = "三级联动模拟", notes = "三级联动模拟")
	@GetMapping("/getAllArea")
	@ResponseBody
	public Result getArea() {
		return areaService.getArea();
	}
	@RequestMapping("/gorealist")
	public String gorealist(){
		return "arealist";
	}


	@RequestMapping("/getpervice")
	@ResponseBody
	public List<Area> privce( ) {
		List<Area> pervice = areaService.getProvince();
		return pervice;
	}
	//根据省份id获取对应市区
	@RequestMapping("/getcity")
	@ResponseBody
	public List<Area> city(@RequestParam(value="pid",required=false) Integer id) {
		List<Area> city = areaService.getCity(id);
		return city;
	}

//	@RequestMapping("/getcity2")
//	@ResponseBody
//	public List<String> city2(@RequestParam(value="pid",required=false) Integer id) {
////		List<Area> city = areaService.getCity(id);
//		List<String> list = new ArrayList<>();
//		list.add("111");
//		list.add("222");
//		list.add("333");
//		return list;
//	}

	//根据市区id获取相应的县区
	@RequestMapping("/getarea")
	@ResponseBody
	public List<Area> area(@RequestParam(value="pid",required=false) Integer id) {
		List<Area> area = areaService.getArea(id);
		return area;
	}
}
